#ifndef TASK_H
#define TASK_H

#include <windows.h>
extern "C"
{
	#include "lua.h"
	#include "lauxlib.h"
	#include "lualib.h"
}

int luaopen_task(lua_State * L);

#define TYPENAME_TASK "task"
#define ERR_MSG_LEN 1024
#define TASK_STS_RUNNING 0
#define TASK_STS_FINISHED 1
#define TASK_STS_ERROR 2

class task
{
public:
	static int Create(lua_State * L);
	static int Print(lua_State * L);
	static void Reg(lua_State * L);
	static HANDLE h_print_mutex;
private:
	lua_State * L;
	char errmsg[ERR_MSG_LEN];
	int sts;
	HANDLE h_thread;
	HANDLE h_mutex;
	static int reg_key;
	static task * Push(lua_State * L);
	static int DoString(lua_State * L);
	static int DoFile(lua_State * L);
	static int Get(lua_State * L);
	static int Set(lua_State * L);
	static int Status(lua_State * L);
	static int ToString(lua_State * L);
	static DWORD WINAPI ThreadProc(LPVOID lpParam);
	static int Suspend(lua_State * L);
};

#endif